/**
 * 
 */
package com.hfjyz.exam.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

import com.hfjyz.exam.service.LoadQuestionService;

/**
 *
 */
public class LoadQuestionController extends SimpleFormController {
	private LoadQuestionService loadQuestionService;

	/**
	 * @return the LoadQuestionService
	 */
	public LoadQuestionService getLoadQuestionService() {
		return loadQuestionService;
	}

	/**
	 * @param LoadQuestionService
	 *            the LoadQuestionService to set
	 */
	public void setLoadQuestionService(LoadQuestionService loadQuestionService) {
		this.loadQuestionService = loadQuestionService;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(javax
	 * .servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse,
	 * java.lang.Object, org.springframework.validation.BindException)
	 */
	@Override
	protected ModelAndView onSubmit(HttpServletRequest request,
			HttpServletResponse response, Object command, BindException errors)
			throws Exception {
		MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
		MultipartFile multipartFile = multipartRequest
				.getFile("loadQuestionAddress");
		loadQuestionService.analyzeQuestionInfo(request, multipartFile, errors);
		if (errors.hasErrors()) {
			return new ModelAndView(getFormView(), errors.getModel());
		}
		return new ModelAndView(getSuccessView(), errors.getModel());
	}
}
